/*
 * Copyright 2010-2014 OBS.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Text;
using System.IO;

namespace OBS.S3.Model
{   
    public class TopicConfiguration
    {
        /// <summary>
        /// Gets and set the Id property. The Id will be provided in the event content and can be used 
        /// to identify which configuration caused an event to fire. If the Id is not provided for the configuration, one will be generated.
        /// </summary>
        public string Id { get; set; }

        internal bool IsSetId()
        {
            return this.Id != null;
        }

        /// <summary>
        /// Bucket event for which to send notifications.
        /// <para>
        /// Topic configurations can now contain multiple events. This property is obsolete in favor of the Events property.
        /// This property will aways get or set the the zeroth element in the Events collection.
        /// </para>
        /// </summary>
        [Obsolete("The Event property is now obsolete in favor the Events property.")]
        public string Event 
        { 
            get
            {
                if (!this.IsSetEvents())
                    return null;

                return this.Events[0];
            }
            set
            {
                if (this.Events == null)
                    this.Events = new List<EventType>();

                if (this.Events.Count == 0)
                    this.Events.Add(value);
                else
                    this.Events[0] = value;
            }
        }
        
        List<EventType> _events;
        /// <summary>
        /// Gets and sets the Events property. These are the events the configuration will listen to and send to the Obs SNS topic.
        /// </summary>
        public List<EventType> Events 
        { 
            get
            {
                if (this._events == null)
                    this._events = new List<EventType>();

                return this._events;
            }
            set { this._events = value; } 
        }

        // Check to see if Event property is set
        internal bool IsSetEvents()
        {
            return this._events != null && this._events.Count > 0;
        }
        
        // Gets and sets the Topic property. Obs SNS topic to which Obs S3 will publish a message to report the specified events for the bucket.
        public string Topic { get; set; }

        // Check to see if Topic property is set
        internal bool IsSetTopic()
        {
            return this.Topic != null;
        }
        public List<FilterRule> filterRuleList;
        /// <summary>
        /// The property of bucket notificationconfiguration
        /// </summary>
        public List<FilterRule> NotificationConfiguration
        {
            get { return this.filterRuleList; }
            set { this.filterRuleList = value; }
        }
        // Check to see if filterfule property is set
        internal bool IsSetFilterRule()
        {
            return this.filterRuleList != null;
        }
    }
}
